package cn.cdiothree.controller;


import cn.cdiothree.dataobject.OrderRating;
import cn.cdiothree.service.OrderRatingService;
import cn.cdiothree.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rating")
public class RatingController {
    @Autowired
    private OrderRatingService orderRatingService;

    /**
     * 添加评分
     * @param orderId
     * @param userId
     * @param ratingExpress
     * @param ratingQuality
     * @param ratingService
     * @return
     */
    @GetMapping("/add")
    public ResultVO addRating(@RequestParam("orderId") String orderId,
                              @RequestParam("userId") Integer userId,
                              @RequestParam("ratingExpress") Integer ratingExpress,
                              @RequestParam("ratingQuality") Integer ratingQuality,
                              @RequestParam("ratingService")Integer ratingService){
        ResultVO orderRating=orderRatingService.addRating(orderId,userId,ratingExpress,ratingQuality,ratingService);
        return ResultVO.success(orderRating);
    }

    /**
     * 查看评分
     * @param orderId
     * @param userId
     * @return
     */
    @GetMapping("/select")
    public ResultVO selectByOrderIdAndUserId(@RequestParam("orderId") String orderId,
                                             @RequestParam("userId") Integer userId){
        OrderRating orderRating = orderRatingService.selectByOrderIdAndUserId(orderId,userId);
        return ResultVO.success(orderRating);

    }
}
